package com.boarsoft.boar.soagov.dir;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.dir.DirExAct;
import com.boarsoft.boar.entity.DirInfo;
import com.boarsoft.flow.store.SimpleFlowStore;

@Component("dirExAct")
public class DirExActImpl implements DirExAct {
	protected Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	protected SimpleFlowStore flowStore;

	@Override
	@Transactional
	public boolean copy(DirInfo od, DirInfo nd) {
		switch (od.getType()) {
		case DirInfo.TYPE_SVC:
		case DirInfo.TYPE_FLOW:
			return flowStore.copy(od.getId(), nd.getId());
		}
		return true;
	}

	@Override
	public boolean move(DirInfo od, DirInfo nd) {
		switch (od.getType()) {
		case DirInfo.TYPE_SVC:
		case DirInfo.TYPE_FLOW:
			return flowStore.move(od.getId(), nd.getId());
		}
		return true;
	}

	@Override
	public boolean delete(DirInfo d) {
		switch (d.getType()) {
		case DirInfo.TYPE_SVC:
		case DirInfo.TYPE_FLOW:
			return flowStore.delete(d.getId());
		}
		return true;
	}
}
